with open(jsonfile, 'w') as fp:
json.dump(data, fp)
open() →開啟
dump() →將python字典寫入JSON檔案
with open(jsonfile, 'r') as fp:
data = json.loap(fp)
如果JSON有中文內容,在open()函式需指定encoding編碼參數是'utf-8',在dump()加上ensure_ascii = False。
with open(jsonfile, 'w', encoding = 'utf-8') as fp
json.dump(book, fp, ensure_ascii = False)